import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const store = new Vuex.Store({
  state:{
    type: 'fancyInfo',
    permissions:[]
  },
  getters:{
    getType:function (state) {
      return state.type;
    },
    getPermissions:function(state) {
      return state.permissions;
    }
  },
  mutations:{
    setType(state,type){
      state.type = type;
    },
    setPermissions:function(state,permissions){
      state.permissions = state.permissions.concat(permissions);
    }
  },
  actions:{
    changetype({commit,state},type) {
      commit('setType',type);
    }
  },
  plugins: [createPersistedState({
      storage: window.sessionStorage,
      reducer(val) {
        return {
            permissions: val.permissions
        }
      }
  })]
})
//console.log(this.$store.getters.getPermissions);
//this.$store.commit('setType','test11232111aaa');  同步，mutations
//this.$store.dispatch("changetype", 'test11232');  异步，actions
export default store